import { get_patient_select } from '@/services/patient';
import { platformuser_select } from '@/services/platformuser';
import { add_edit_sickbed, get_sickbed_patient_select } from '@/services/sickbeds';
import { ActionType, CheckCard, ProForm, ProFormRadio, ProFormSelect, ProFormText } from '@ant-design/pro-components';
import { Divider, Form, Modal, Radio, Result, Tag, message } from 'antd';
import React from 'react'
import './index.less'

interface Iprops {
    isShowAddModal: (show: boolean) => void;
    isAddModalOpen: boolean;
    actionRef: React.MutableRefObject<ActionType | undefined>;
}
const AddSickbeds = (props: Iprops) => {
    const { isAddModalOpen, isShowAddModal, actionRef } = props

    // 获取机构下全部患者
    const get_platform_patient = async () => {
        let params = await get_sickbed_patient_select();
        console.log('全部患者', params);
        let res: any = [];
        params.data.map((item: { username: string; id: string, phone: string, id_card: string }) => {
            let temp: any = {};
            temp['label'] = item.username + '/' + item.phone + '/' + item.id_card;
            temp['value'] = parseInt(item.id);
            res.push(temp);
        });
        return res;
    }
    // 获取责任医生
    const getDoctor = async () => {
        let params = await platformuser_select();
        console.log('医生', params);
        let res: any = [];
        params.data.map((item: { username: string; id: string }) => {
            let temp: any = {};
            temp['label'] = item.username;
            temp['value'] = parseInt(item.id);
            res.push(temp);
        });
        return res;
    }
    // 新建病床
    const add_sick_beds = async (values: any) => {
        let request_body = {
            ...values,
            doctor_ids:JSON.stringify(values.doctor_ids)
        }
        console.log('values', request_body);
        let params: any = await add_edit_sickbed(request_body)
        if (params.code == 200) {
            // 关闭弹窗
            actionRef.current?.reload();
            message.success('新建成功');
            isShowAddModal(false);
            //刷新列表
        } else {
            message.error(params.msg);
        }
    }

    return (
        <Modal
            title="新增病床"
            open={isAddModalOpen}
            onCancel={() => isShowAddModal(false)}
            width={500}
            destroyOnClose={true}
            footer={null}
            centered
        >
            <Divider />
            <ProForm
                layout="horizontal"
                labelCol={{ span: 5 }}
                wrapperCol={{ span: 20 }}
                onReset={() => isShowAddModal(false)}
                onFinish={(value) => add_sick_beds(value)}
                submitter={{
                    // 配置按钮文本
                    searchConfig: {
                        resetText: '取消',
                        submitText: '提交',
                    },
                    resetButtonProps: {
                        style: {
                            display: 'block',
                            position: 'absolute',
                            left: 'calc(50% - 107px)',
                        },
                    },
                    submitButtonProps: {
                        style: {
                            display: 'block',
                            position: 'absolute',
                            right: 'calc(50% - 107px)',
                        },
                    },
                }}
            >
                <ProFormText
                    name="code"
                    label="病床编号"
                    placeholder="请输入病床编号"
                    rules={[
                        { required: true, message: '请输入病床编号' },
                        { pattern: /(^\S)((.)*\S)?(\S*$)/, message: '不能输入空格' },
                        { max: 10, message: '病床编号最多10位' },
                        { pattern: /^[^\u4e00-\u9fa5]{1,}$/, message: "病床编号不允许输入汉字" }
                    ]}
                />
                <ProFormSelect
                    name="patient_id"
                    label="绑定患者"
                    request={async () => get_platform_patient()}
                    placeholder="请选择患者"
                    fieldProps={{
                        showSearch: true,
                        filterOption: (input: any, option: any) =>
                            (option?.label ?? '').toLowerCase().includes(input.toLowerCase())
                    }}
                />
                <ProFormSelect
                    name="doctor_ids"
                    mode="multiple"
                    label="责任医生"
                    request={async () => getDoctor()}
                    placeholder="请选择责任医生"
                    fieldProps={{
                        showSearch: true,
                        filterOption: (input: any, option: any) =>
                            (option?.label ?? '').toLowerCase().includes(input.toLowerCase())
                    }}
                />
                <Form.Item
                    name="level"
                    label="风险等级">
                    <CheckCard.Group
                        onChange={(value) => {
                            console.log('value', value);
                        }}
                    >
                         <CheckCard title="一般关注" value={1} style={{ width: 100, height: 40,backgroundColor:'rgba(0, 98, 255,0.7)' }} />
                        <CheckCard title="中等关注" value={2} style={{ width: 100, height: 40,backgroundColor:'rgba(245, 221, 30,0.7)' }} />
                        <CheckCard title="重点关注" value={3} style={{ width: 100, height: 40,backgroundColor:'rgba(247, 10, 10,0.7)' }} />
                    </CheckCard.Group>
                </Form.Item>

                <br />
            </ProForm>
            <br />
        </Modal>
    )
}
export default AddSickbeds